package cw.spring.security.acl.poc.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.hibernate.validator.Pattern;

@Entity
@Table(name = "NorthUser", uniqueConstraints = { @UniqueConstraint(columnNames = { "id" }) })
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class NorthUserModel {

  private long id;
  private String name; // name of the group

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  public long getId() {
    return id;
  }

  public void setId(long id) {
    this.id = id;
  }

  private String password; // password of the user (hashed)
  private Boolean enabled; // whether this account is disabled
  private TraderModel trader; // the related trader, can be null

  @NotNull
  @Length(min = 1, max = 256, message = "The user name must have a length superior or equals to 1")
  @Pattern(regex = "[a-zA-Z0-9_]*", message = "The user name must be composed of characters, numbers or underscores (upper or lower case)")
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @NotNull
  @Length(min = 4, max = 256, message = "The password must have a length superior or equals to 4")
  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  @NotNull
  public Boolean getEnabled() {
    return enabled;
  }

  public void setEnabled(Boolean enabled) {
    this.enabled = enabled;
  }

  @ManyToOne
  @JoinColumn(name = "trader_id", nullable = true)
  public TraderModel getTrader() {
    return trader;
  }

  public void setTrader(TraderModel trader) {
    this.trader = trader;
  }
}
